//1. 类装饰器 ClassDecorator
//2. 属性装饰器 PropertyDecorator
//3.参数装饰器 ParameterDecorator
//4.方法装饰器 MethodDecorator
//5.装饰器工厂
//6.import 'reflect-metadata'
//7.axios

// 1.0
// const Base:ClassDecorator = (target) =>{
//     // targe   Http的构造函数      [class Http]
//     console.log(target)
//     // 拿到构造函数，可以不破坏内部代码的同时，在其原型上添加属性和方法
//     target.prototype.__attr = '属性'
//     target.prototype.__method = function(){
//         console.log('我是方法！')
//     }
// }

// @Base   //编译阶段自已调用，不用手动调用
// class Http{

// }

// Base(Http)
// const http = new Http() as any
// console.log(http.__attr)
// http.__method()

import 'reflect-metadata'
import axios from "axios" 
const Base = (name: string) => {
    const fn: ClassDecorator = (target) => {
        // targe   Http的构造函数      [class Http]
        console.log(target)
        // 拿到构造函数，可以不破坏内部代码的同时，在其原型上添加属性和方法
        target.prototype.__attr = name
        target.prototype.__method = function () {
            console.log('我是方法！')
        }
    }
    return fn
}
const Get = (url: string) => {
    const fn:MethodDecorator = (target,_:any,descriptor:PropertyDecorator)=>{
        const key = Reflect.getMetadata('ket',target)
        axios.get(url).then(res=>{
            descriptor.value(key?res.data[key]:res.data)
        })
    }
    return fn
}

const Post = () =>{
    const fn:MethodDecorator = () =>{

    }
    return fn
}
const Result = () =>{
    const fn:ParameterDecorator = (target,key,index) =>{
        Reflect.defineMetadata('Key','result',target)
        console.log(target,key,index)
    }
    return fn
}

@Base('wssg')   //编译阶段自已调用，不用手动调用
class Http {
    @Get('https://api.apiopen.top/api/getHaoKanvideo?page=0&size=10')
    getList(@Result() data:any) {
        // console.log(data.result.list)
        console.log(data)
    }

    @Post()
    create() {

    }

}
const http = new Http() as any
console.log(http.__attr)
http.__method()

